#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2011-6-15

@author: drowning
'''

from jiaju.model import Privilege, Article
from jiaju.common.db import connection


def get_article_list(page,pagesize):
    total = Article.count()
    start = (page-1) * pagesize
    cursor = connection.cursor()
    sql = "SELECT t.name as tname,a.* FROM article AS a , TYPE AS t WHERE t.id=a.style_id ORDER BY created_time DESC limit %s,%s"%(start,pagesize)
    article_list = cursor.fetchall(sql=sql)
    return total,article_list


def get_article_one(id):
    return Article.load(id=id)